package com.mingdong.first.mingling.control;

import java.util.Stack;

import com.mingdong.first.mingling.commond.Commond;
import com.mingdong.first.mingling.commond.NoCommon;

public class CommanModeControl implements Control {

	private Commond[] onCommonds;
	private Commond[] offCommonds;
	private Stack<Commond> stack = new Stack<Commond>();
	
	public CommanModeControl(){
		
		NoCommon noCommon = new NoCommon();
		onCommonds = new Commond[5];
		offCommonds = new Commond[5];
		for(int i = 0;i < onCommonds.length;i++){
			onCommonds[i] = noCommon;
			offCommonds[i] = noCommon;
		}
	}
	
	public void setCommon(int slow,Commond onCommond,Commond offCommond){
		
		onCommonds[slow] = onCommond;
		offCommonds[slow] = offCommond;
		
	}
	
	public void onButton(int slow) {
		
		onCommonds[slow].execute();
		stack.push(onCommonds[slow]);
	}

	public void offButton(int slow) {
		
		offCommonds[slow].execute();
		stack.push(offCommonds[slow]);
	}

	public void undoButton() {
		stack.pop().undo();
	}

}
